package sign_in.loginsystem.controller;


import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import sign_in.loginsystem.annotation.Permissions;
import sign_in.loginsystem.model.util.RBody;
import sign_in.loginsystem.model.util.Result;
import sign_in.loginsystem.service.port.DepartmentImplement;
import sign_in.loginsystem.tool.Analyze;

@Slf4j
@RestController
public class DepartmentController {



    @Autowired
    Analyze analyze;



    @Autowired
    DepartmentImplement department;


    @PostMapping("/department")
    @Permissions(permission = "dept:list")
    public Result allDepartment(@RequestBody RBody body){
       return Result.success(department.allDepartment(body));
    }

    @PostMapping("/departmentR")

    public Result allDepartmentR(){
        return Result.success(department.registerAnOptionalDept());
    }

    @PostMapping("/department/users")
    @Permissions(permission = "dept:user")
    public Result departmentUser(@RequestBody RBody body){
        return Result.success(department.searchUserByDepartmentId(body));
    }

    @PostMapping("/department/create")
    @Permissions(permission = "dept:create")
    public Result createDepartment(@RequestBody RBody body){
        return Result.success(department.createDepartment(body));
    }

    @PostMapping("/department/editor")
    @Permissions(permission = "dept:edit")
    public Result editDepartment(@RequestBody RBody body){
        return Result.success(department.editDepartment(body));
    }

    @PostMapping("/department/delete")
    @Permissions(permission = "dept:delete")
    public Result delDepartment(@RequestBody RBody body){
        return Result.success(department.delDepartment(body));
    }


}
